//
//  TeacherIndexCell.m
//  YXFinance
//
//  Created by uplooking on 2018/10/24.
//  Copyright © 2018年 CRLong. All rights reserved.
//

#import "TeacherIndexCell.h"

@interface TeacherIndexCell()
{
    UIImageView * imageView;
    UILabel * labelTitle;
    UILabel * labelPeople;
    TeacherIndexModel * teacherModel;
    UILabel * addteam;
}
@end

@implementation TeacherIndexCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self initView];
    }
    
    return self;
    
}

- (void)initView{
    
    imageView = [[UIImageView alloc]init];
    [self addSubview:imageView];
    [imageView.layer setMasksToBounds:YES];
    [imageView.layer setBorderWidth:0.5];
    [imageView.layer setCornerRadius:7 * kAutoScanleX];
    [imageView.layer setBorderColor:HexRGBA(0xe9e9e9, 1).CGColor];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self).offset(15 * kAutoScanleX);
        make.size.mas_equalTo(CGSizeMake(100 * kAutoScanleX, 74 * kAutoScanleX));
    }];

    
    labelTitle = [[UILabel alloc]init];
    [labelTitle setTextColor:HexRGBA(0x000000, 1)];
    [labelTitle setFont:[UIFont systemFontOfSize:17 * kAutoScanleX]];
    [labelTitle setTextAlignment:NSTextAlignmentLeft];
    [self addSubview:labelTitle];
    [labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imageView.mas_right).offset(15 * kAutoScanleX);
        make.top.equalTo(imageView).offset(10 * kAutoScanleX);
    }];
    
    
    labelPeople = [[UILabel alloc]init];
    [labelPeople setTextColor:HexRGBA(0xa4a4a4, 1)];
    [labelPeople setFont:[UIFont systemFontOfSize:12 * kAutoScanleX]];
    [labelPeople setTextAlignment:NSTextAlignmentLeft];
    [self addSubview:labelPeople];
    [labelPeople mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(imageView.mas_right).offset(15 * kAutoScanleX);
        make.bottom.equalTo(imageView).offset(-10 * kAutoScanleX);
    }];
    
     addteam =  [[UILabel alloc]init];
    [addteam setBackgroundColor:HexRGBA(0xbc9a6d, 1)];
    [addteam setText:@"加入战队"];
    [addteam setTextColor:HexRGBA(0xffffff, 1)];
    [addteam setFont:[UIFont systemFontOfSize:13 * kAutoScanleX]];
    [addteam setTextAlignment:NSTextAlignmentCenter];
    [addteam.layer setMasksToBounds:YES];
    [addteam.layer setCornerRadius:4 * kAutoScanleX];
    [self addSubview:addteam];
    [addteam mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.right.equalTo(self).offset(-15 * kAutoScanleX);
        make.size.mas_equalTo(CGSizeMake(84 * kAutoScanleX, 30 * kAutoScanleX));
    }];
    
    
//    UIButton * button = [[UIButton alloc]init];
//    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
//    [self addSubview:button];
//    [button mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.edges.equalTo(addteam);
//    }];

    
    UIView *line = [[UIView alloc]init];
    [line setBackgroundColor:HexRGBA(0xe9e9e9, 1)];
    [self addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self);
        make.left.right.equalTo(self).inset(15 * kAutoScanleX);
        make.height.mas_equalTo(0.5);
    }];
    
}

#pragma mark -- 加入战队
- (void)buttonAction:(UIButton *)sender{
    
    if (self.blockAddTeamRandom) {
        
        self.blockAddTeamRandom(teacherModel);
    }
    
}

-(void)setModel:(TeacherIndexModel *)model{
    
    teacherModel = model;
    [imageView sd_setImageWithURL:[NSURL URLWithString:model.litpic] placeholderImage:[UIImage imageNamed:@"bg_list_moren"]];
    [labelTitle setText:model.teacher_name];
    [labelPeople setText:[NSString stringWithFormat:@"%@ 人",model.students]];
    
}

-(void)setChooseModel:(TeacherIndexModel *)chooseModel{
    
    [imageView sd_setImageWithURL:[NSURL URLWithString:chooseModel.litpic] placeholderImage:[UIImage imageNamed:@"bg_list_moren"]];
    [labelTitle setText:chooseModel.teacher_name];
    [labelPeople setText:[NSString stringWithFormat:@"%@ 人",chooseModel.students]];
    [addteam setHidden:YES];
}


@end
